//搭建koa服务器;
import Koa from 'koa';
import path from 'path';
import routers from './router/router';
import bodyParser from "koa-bodyparser";
import KoaStatic from 'koa-static';

//导入监听接口状态的方法;
import log from './middle/log';
import isLogin from './middle/isLogin';
//
import isJudge from './untils/verfiyrole';
//MySQL语法;
import db from './db';
const {querys,select,insert,update}=db;

const app =new Koa();

app.context.db={querys,select,insert,update};
app.context.isJudge = isJudge;

//处理静态资源;
app.use(KoaStatic(path.join(__dirname,'./public')));
//处理post请求;
app.use(bodyParser());
//监听接口状态;
app.use(log());
//鉴权;
app.use(isLogin());
//路由;
app.use(routers.routes());
app.use(routers.allowedMethods());

const server=app.listen(8000,console.log(`成功开启：http://192.168.1.198:8000`));
//解决超时；
//在koa源目录下的lib下application.js文件中的第149行加入了settimeout为0;
server.setTimeout(0);//暂定没用
